#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void printVector(vector<int> v);
void priVec(vector<int> v);
/*
b站学习STL
*/
int main()
{
#if 0 
   int a[] = {1, 2, 3, 4};
    vector<int> vec(a, a + 4);
    printVector(vec);
    vec.push_back(100);
    printVector(vec);
    vec.pop_back();
    cout << vec.at(vec.size() - 1) << endl;
    printVector(vec);
    cout << "front:" << vec.front() << " back:" << vec.back() << endl;
    vec.insert(vec.begin() + 3, 12);
    printVector(vec);
    vec.insert(vec.begin() + 5, a, a + 4);
    printVector(vec);
    vec.insert(vec.begin(), 10, 1);
    printVector(vec);
    vec.assign(10, 2);
    printVector(vec);
    vec.assign(a, a + 4);
    printVector(vec);

    vector<int>::iterator it;
    it = vec.begin();
    priVec(vec);
    vec.erase(vec.begin(), vec.begin() + 2);
    priVec(vec);
    vec.assign(a, a + 4);
    priVec(vec);
    remove(vec.begin(), vec.end(), 3);
    priVec(vec);
#endif
#if 0
    vector<int> v{1, 2, 3, 4};
    priVec(v);
    remove(v.begin(),v.end(),3);
    priVec(v);
#endif
#if 0
    // 如何通过迭代器删除指定元素
    vector<int> v{1, 2, 3, 3, 3, 3, 3, 5, 4, 6};
    vector<int>::iterator it;
    for (it = v.begin(); it != v.end();)
    {
        if (*it == 3)
        {
            v.erase(it);
        }
        else
            it++;
    }
    priVec(v);
#endif
    return 0;
}
void printVector(vector<int> v)
{
    for (int i = 0; i < v.size(); i++)
    {
        cout << v.at(i) << " ";
    }
    cout << endl;
}
void priVec(vector<int> v)
{
    for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
    {
        cout << *it << " ";
    }
    cout << endl;
}